<#include '/admin/header.html'>

	<#assign image="com.enation.framework.directive.ImageDirectiveModel"?new()>
<style>
.layui-form-select {
	width: 50%;
}

.layui-select-title input {
	width: 100%;
}

.layui-form-pane .layui-form-label {
	width: 200px;
	margin-left: 20px;
}

.layui-form-pane .layui-input-block {
	float: left;
	margin: 0 0 0 10px;
	width: 60%;
}
</style>
<div class="admin-main">
	<!--表单区域  -->
	<form id="editpayCfgForm" class="layui-form layui-form-pane" action="" enctype="multipart/form-data"
		style="padding-top: 10px; padding-bottom: 10px;">
		<input type="hidden" name="method_id" value="${paymentPlugin.method_id}"> 
		<input type="hidden" name="plugin_id" value="${paymentPlugin.plugin_id}">
		<div class="layui-form-item" id="name">
			<label class="layui-form-label">支付方式名称</label>
			<div class="layui-input-block">
				<input type="text" name="method_name"
					value="${paymentPlugin.method_name}" maxlength="20" lay-verify=""
					lay-verify="required" autocomplete="off" class="layui-input">
			</div>
		</div>

		<#list paymentPlugin.configItems as item>
		<div class="layui-form-item config">
			<label class="layui-form-label">${item.text}</label>
			<div class="layui-input-block">
				<input type="text" configname="${item.name!''}" name=""
					value="${item.value!''}" lay-verify=""
					lay-verify="required" autocomplete="off" class="layui-input">
			</div>
		</div>
		</#list>
		<#if paymentPlugin.plugin_id == "weixinPayPlugin">
			<div class="" >
				<label class="layui-form-label"></label>
				<div class="">
					<em style="color: red;">请正确配置证书路经，否则原路退回功能失效,如G:/apiclient_cert.p12</em>
				</div>
			</div>
		</#if>
		<div class="layui-form-item" id="online">
			<label class="layui-form-label">启用PC</label>
			<div class="layui-input-block">
				<input type="radio" name="pc_enable" value="YES" title="启用"
				<#if paymentPlugin.pc_enable=='YES'>checked </#if>
				> <input type="radio" name="pc_enable" value="NO" title="禁用"
				<#if paymentPlugin.pc_enable=='NO'>checked </#if>
				>
			</div>
		</div>
		<div class="layui-form-item" id="online">
			<label class="layui-form-label">启用WAP</label>
			<div class="layui-input-block">
				<input type="radio" name="wap_enable" value="YES" title="启用"
				<#if paymentPlugin.wap_enable=='YES'>checked </#if>
				> <input type="radio" name="wap_enable" value="NO" title="禁用"
				<#if paymentPlugin.wap_enable=='NO'>checked </#if>
				>
			</div>
		</div>
		<div class="layui-form-item" id="online">
			<label class="layui-form-label">启用APP</label>
			<div class="layui-input-block">
				<input type="radio" name="app_enable" value="YES" title="启用"
				<#if paymentPlugin.app_enable=='YES'>checked </#if>
				> <input type="radio" name="app_enable" value="NO" title="禁用"
				<#if paymentPlugin.app_enable=='NO'>checked </#if>
				>
			</div>
		</div>
		<div class="layui-form-item" id="online">
			<label class="layui-form-label">是否支持原路退回</label>
			<div class="layui-input-block">
				<input type="radio" name="is_retrace" value="1" title="是"
				<#if paymentPlugin.is_retrace==1>checked </#if>
				> <input type="radio" name="is_retrace" value="0" title="否"
				<#if paymentPlugin.is_retrace==0>checked </#if>
				>
			</div>
		</div>
		<div class="layui-form-item" id="img">
			<label class="layui-form-label">展示图片</label>
			<div class="layui-input-block">



				<@image src="${paymentPlugin.img_url!''}" id="showfile" style='' /><br/>
				<input type="hidden" name="img_url" value="${paymentPlugin.img_url!''}" >
				<input name="file" class="layui-upload-file" type="file" id="uploadImgBtn" >


			</div>
		</div>

		<div class="layui-form-item" id="button">
			<div class="layui-input-block padding-bottom" align=center>
				<a class="layui-btn" href="javascript:void(0)" lay-submit=""
					lay-filter="editPay">立即提交</a>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">	
var index = parent.layer.getFrameIndex(window.name);
layui.use(['form','upload','layedit', 'laydate'], function(){
    var form = layui.form()
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate
		,upload = layui.upload;

    //监听提交
    form.on('submit(editPay)', function(){
    	var active  = $("form").serializeJson();
    	
    	var configItems = [];
    	$(".config").each(function(){
    		var config = {};
    		config.text = $(this).find(".layui-form-label").text();
    		config.value =$(this).find(".layui-input-block input").val();
    		config.name = $(this).find(".layui-input-block input").attr("configname");
    		config.type = "";
    		configItems.push(config);
    	});
    	active.configItems = configItems;

    	$.ajax({
			url : "${ctx}/order-pay/admin/payment/save.do",
			type : "POST",
			contentType: "application/json",
			data:JSON.stringify(active),
			success : function(result) {
				$.Loading.success("操作成功");
				newTab("支付方式","${ctx}/shop/admin/paymethod/list.do");
			},
			error : function(e) {
                $.error(e.responseJSON.error_message);
			}
    	})
		return false; 
    });


    var uploadInst = upload({
        url: '${ctx}/eop/upload/upload-file.do?ajax=1&subFolder=pay'
        ,elem: '#uploadImgBtn' //指定原始元素，默认直接查找class="layui-upload-file"
        ,method: 'post' //上传接口的http类型
        ,success: function(res){
            //logofile.src = res.path;
            $("input[name=img_url]").val(res.path);
            $("#showfile").attr("src",res.path);
        }
    });
});  

$(function() {
//	var options;
//	if("${paymentPlugin.method_id}"!="0"){
//		options ={
//	          //文件上传成功后回调
//	           success:function(data,ele){
//	        	   $("input[name=img_url]").val(data);
//	           },error:function(error){
//	               console.log(error);
//	           }
//	      }
//	}else{
//		options={
//		        //文件上传成功后回调
//		      success:function(data,ele){   // 本回调函数已更新，但兼容旧版本。（推荐用最新写法）
//		         $("input[name=img_url]").val(data);
//		      },error:function(error){
//		          console.log(error);
//		      }
//		  }
//	}
//    $("#uploadImgBtn").click(function(){
//        layui.upload({
//            url: '${ctx}/eop/upload/upload-file.do?ajax=1&subFolder=pay'
//            ,elem: '#uploadImgBtn' //指定原始元素，默认直接查找class="layui-upload-file"
//            ,method: 'post' //上传接口的http类型
//            ,success: function(res){
//                //logofile.src = res.path;
//                $("input[name=img_url]").val(res.path);
//                $("#showfile").attr("src",res.path);
//            }
//        });
//    });
    //$('.upload-btn1').FilesUpload(options);
})

</script> 
<#include '/admin/footer.html'>